﻿@using Huirui.Cavan.Domain.MainBoundedContext.SystemModule
@model Huirui.Cavan.Presentation.ViewModel.SystemModule.ICustomerViewModel
@{Layout = null;}
@using (Html.BeginForm(ActionConst.SEARCH, ControllerConst.CUSTOMER, FormMethod.Post))
{
    <div class="tool_bar">
        <input id="customer_list" type="submit" value="query" style="display: none;" />
        <input id="custlist_reset" type="reset" style="display: none" />
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-undo'" id="customerlist_reset">重置</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="javascript:$('#customer_list').click()">查询</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-collapse'" onclick="toggleHeard()">折叠/展开</a>
    </div>
       
    <table class="form_heard">
        <tr>
            <td class="c100">
                <label>名称:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.SearchParam.Name, new { id = "custlist_name" })
            </td>
            <td class="c100">
                <label>类别:</label>
            </td>
            <td class="c160">
                @Html.DropDownListFor(m => m.SearchParam.AgentTypeID, typeof(SystemIdentifier.AgentType), new { id = "custlist_agenttype" })
            </td>
        </tr>
        <tr>
            <td class="c100">
                <label>联系人:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.SearchParam.Contact, new { id = "custlist_contact" })
            </td>
            <td class="c100">
                <label>所属地区:</label>
            </td>
            <td class="c160">
                @{ Html.RenderAction(ActionConst.SELECTAREA, ControllerConst.AREA, new { purpose = "ForCustomerList", cityID = @Model.CityID, provinceID = @Model.ProvinceID }); }
                @Html.HiddenFor(m => m.SearchParam.AreaCode, new { id = "areaForCustomerList" })
            </td>
        </tr>
    </table>
}
<table id="customerlist_dg">
</table>
<div id="custlisttb">
    <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" id="deleteCustomer">选择删除</a>
    <a href="#" class="easyui-linkbutton" iconcls="icon-print" plain="true" onclick="javascript:alert('打印列表')">打印列表</a>
    <a href="#" class="easyui-linkbutton" iconcls="icon-excel" plain="true" onclick="javascript:alert('引出')">引出</a>
</div>
<script type="text/javascript">
    $(function ()
    {
        $('#customerlist_dg').datagrid({
            idfield: 'Id',
            toolbar: '#custlisttb',
            title: '客户档案列表',
            singleSelect: 'true',
            selectOnCheck: 'true',
            fitColumns: 'true',
            pagination: 'true',
            columns: [[
         { field: 'ck', checkbox: true, width: 10 },
         { field: 'Id', title: '客户编号', width: 80, formatter: function (value,rec)
         {
             return '<a onclick=addTab("客户档案","center_tt","/customer/detail/?customerid=' + value + '") href="#">' + value + '</a>';
         }
         },
         { field: 'Name', title: '名称', width: 80 },
         { field: 'AgentType', title: '类别', width: 80 },
         { field: 'Area', title: '地区', width: 80 },
         { field: 'Contact', title: '业务员', width: 80 },
         { field: 'PayType', title: '付款方式', width: 80 },
         { field: 'PayDay', title: '账期', width: 80 },
         { field: 'CreditLimit', title: '信用额度', width: 80 },
         { field: 'InvoiceType', title: '开票类型', width: 80 }
                     ]]
        });

        $("form[action^='/customer']").submit(function ()
        {
            $("#areaForCustomerList").val($("#cityForCustomerList").val());
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result)
                {
                    if (result.total > 0)
                    {
                        $('#customerlist_dg').datagrid({
                            data: result
                        });
                    }
                    else
                    {
                        $('#customerlist_dg').datagrid('loadData', { total: 0, rows: [] });
                    }
                },
                error: function ()
                {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $("#deleteCustomer").bind("click", function ()
        {
            if ($('#customerlist_dg').datagrid('getChecked').length)
            {
                var selected = $('#customerlist_dg').datagrid('getChecked');
                var effectRow = new Object();
                if (selected.length)
                {
                    effectRow["selected"] = JSON.stringify(selected);
                }

                $.post("/CUSTOMER/DELETE", effectRow, function (data)
                {
                    if (data.IsSuccess)
                    {
                        $('#customerlist_dg').datagrid('reload');
                        for (var i = effectRow.length - 1; i >= 0; i--)
                        {
                            var index = $('#customerlist_dg').datagrid('getRowIndex', effectRow[i]);
                            $('#customerlist_dg').datagrid('deleteRow', index);
                        }
                        $('#customerlist_dg').datagrid('clearSelections');
                    }
                }, "JSON").error(function ()
                {
                    $.messager.alert("提示", "网络异常，请稍候再试");
                });
            }
        });


        $("#provinceForCustomerList").bind("change", function () { getSelectItem($("#provinceForCustomerList").val(), $("#cityForCustomerList")) });
        //        $("#cityForCustomerList").bind("change", function () { getAreaValue("areaForCustomerList", $(this).val()) });
    });
</script>
